AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:SpawnFunction(ply, tr)
	local SpawnPos = tr.HitPos + tr.HitNormal * 42
	ang = ply:EyeAngles()
	ang.pitch = 0
	ang.roll = 0
	local vehiclespawn = ents.Create("prop_vehicle_airboat")
	vehiclespawn:SetModel("models/airboat.mdl")
	vehiclespawn:SetKeyValue("vehiclescript", "scripts/vehicles/airboat.txt")
	vehiclespawn:SetKeyValue("solid", 6)
	vehiclespawn:SetKeyValue("VehicleLocked", 0)
	vehiclespawn:SetKeyValue("EnableGun", 1)
	vehiclespawn:SetPos(SpawnPos)
	vehiclespawn:SetAngles(ang)
	vehiclespawn:Spawn()
	vehiclespawn:Activate()
	vehiclespawn.HP = 300
	vehiclespawn.PhysgunPickup = function () return false end
	vehiclespawn.GravGunPickupAllowed = function () return false end
	vehiclespawn.GravGunPunt = function () return false end
	return ent
end

function AirBoatDamage( ent, inflictor, attacker, amount, dmginfo)
	if(attacker:GetClass() == "prop_vehicle_airboat" && inflictor != attacker && (!dmginfo:IsDamageType(DMG_VEHICLE) || !dmginfo:IsDamageType(DMG_CRUSH))) then dmginfo:SetDamage(5) end 
	if(ent:GetClass() == "prop_vehicle_airboat") then
		ent.HP = ent.HP - dmginfo:GetDamage()
		if(ent.HP < 75) then ent:Ignite(15) end
		if(ent.HP < 0) then 
			local effectdata = EffectData()
			effectdata:SetStart(ent:GetPos())
			effectdata:SetOrigin(ent:GetPos())
			effectdata:SetScale(1)
			util.Effect("HelicopterMegaBomb", effectdata)
			ent:Remove() 
		end
	end
end
hook.Add("EntityTakeDamage", "AirBoatDamage", AirBoatDamage)